//
//  AfNetWorkingManager.m
//  GTMDBTest
//
//  Created by dllo on 15/11/25.
//  Copyright © 2015年 zxx. All rights reserved.
//

#import "AfNetWorkingManager.h"
#import <AFHTTPSessionManager.h>

@interface AfNetWorkingManager ()

@property (nonatomic, strong) NSDictionary *dic;

@end

@implementation AfNetWorkingManager

#pragma mark - Singleton

+ (AFHTTPSessionManager *)sharedManager {
    static AFHTTPSessionManager *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[AFHTTPSessionManager alloc] init];
    });
    return manager;
}

#pragma mark - get

+ (void)getInfoWithUrl:(NSString*)url
                    block:(void (^)(NSDictionary * resultDic, NSError *error))block{
    
    AFHTTPSessionManager *manager = [self sharedManager];
    [manager GET:url parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSDictionary *dic = [NSDictionary dictionary];
        dic = responseObject;
        
        if (block && dic) {
            block(dic, nil);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil, error);
    }];
    
}



#pragma mark - post

+ (void)postWithParameters:(NSDictionary *)Parameters
                    Url:(NSString *)url
                     block:(void (^)(NSDictionary *resultDic, NSError *error))block {
    [[self sharedManager] POST:url parameters:Parameters success:^(NSURLSessionDataTask *task, id responseObject) {
        block(responseObject, nil);
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        block(nil, error);
    }];
    
}
@end
